function schedule = generate_l0_constrained_schedule(G, code_map)
    in_degrees = indegree(G);
    ready_list = find(in_degrees == 0)';
    schedule = [];
    l0_active = zeros(1, 3);
    while length(schedule) < numnodes(G)
        node_to_schedule = -1; node_index_in_list = -1;
        for i = 1:length(ready_list)
            node_id = ready_list(i);
            op = G.Nodes.OpCode(node_id); type = G.Nodes.TypeCode(node_id);
            is_schedulable = true;
            if isequal(op, code_map.op.ALLOC)
                if isequal(type, code_map.type.L0A) && l0_active(1)>0, is_schedulable = false; end
                if isequal(type, code_map.type.L0B) && l0_active(2)>0, is_schedulable = false; end
                if isequal(type, code_map.type.L0C) && l0_active(3)>0, is_schedulable = false; end
            end
            if is_schedulable, node_to_schedule = node_id; node_index_in_list = i; break; end
        end
        if node_to_schedule == -1, error('调度死锁!'); end
        ready_list(node_index_in_list) = [];
        schedule(end+1) = node_to_schedule;
        op = G.Nodes.OpCode(node_to_schedule); type = G.Nodes.TypeCode(node_to_schedule);
        if isequal(op, code_map.op.ALLOC)
            if isequal(type, code_map.type.L0A), l0_active(1)=l0_active(1)+1; end
            if isequal(type, code_map.type.L0B), l0_active(2)=l0_active(2)+1; end
            if isequal(type, code_map.type.L0C), l0_active(3)=l0_active(3)+1; end
        elseif isequal(op, code_map.op.FREE)
            if isequal(type, code_map.type.L0A), l0_active(1)=l0_active(1)-1; end
            if isequal(type, code_map.type.L0B), l0_active(2)=l0_active(2)-1; end
            if isequal(type, code_map.type.L0C), l0_active(3)=l0_active(3)-1; end
        end
        for succ = successors(G, node_to_schedule)'
            in_degrees(succ) = in_degrees(succ) - 1;
            if in_degrees(succ) == 0, ready_list(end+1) = succ; end
        end
    end
end

